//
//  LBOldFilter.mm
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 12/14/12.
//  Copyright (c) 2012 UIT. All rights reserved.
//

#include "LBOldFilter.h"
#include "LBTexture.h"
#include "LBSaturationFilter.h"
#import "OCImage.h"
#include "LBLinearLineTextureFilter.h"
#include "LBOverlayTextureFilter.h"
#include "LBOverlayColorFilter.h"
#include "LBExclusionColorFilter.h"
#include "LBUtils.h"

LBOldFilter::LBOldFilter(){
    
    saturation = new LBSaturationFilter();
    saturation->setSaturation(0.0);
    
    OCImage* ocImg = [[OCImage alloc] initWithFileName:@"old_pattern.png"];
    oldTexture = new LBTexture([ocImg imageData], [ocImg width], [ocImg height], [ocImg byteInAPixel]);
    oldTexture->setLocationAndScale(0.0f, 0.0f, 1.0f, 1.0f);
    [ocImg release];
    
    linearLineOldTexture = new LBLinearLineTextureFilter();
    linearLineOldTexture->setOpactiy(0.1);
    linearLineOldTexture->setBlendTexture(oldTexture);
    
    gradientOverlay = new LBOverlayTextureFilter();
    gradientOverlay->setOpactiy(0.4);
    
    exclusion = new LBExclusionColorFilter();
    exclusion->setColor(0.173, 0.145, 0.369);
    exclusion->setOpactiy(0.5);
    
    overlayColor = new LBOverlayColorFilter();
    overlayColor->setColor(0.565, 0.471, 0.471);
    overlayColor->setOpactiy(0.3);
    
    saturation->addTarget(linearLineOldTexture)->addTarget(gradientOverlay)->addTarget(exclusion)->addTarget(overlayColor);
    firstFilter = saturation;
}

LBOldFilter::~LBOldFilter(){
    outputTexture = 0;
    DELETE_SAFELY(saturation);
    DELETE_SAFELY(gradientOverlay);
    DELETE_SAFELY(linearLineOldTexture);
    DELETE_SAFELY(exclusion);
    DELETE_SAFELY(overlayColor);
    DELETE_SAFELY(oldTexture);
}

void LBOldFilter::setBlendTexture(LBTexture* blendTexture){
    gradientOverlay->setBlendTexture(blendTexture);
}